<template>
  <div class="page">
    <h2>新闻内容页面</h2>
    <el-table v-loading="loading" :data="newsData" style="width: 100%">
      <el-table-column prop="word" label="标题"/>
      <el-table-column prop="createTime" label="记录时间"/>
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted, onActivated } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { BASE_URL, API_PATH } from '@/config/api'

const newsData = ref([])
const loading = ref(false)

const fetchData = async () => {
  try {
    loading.value = true
    const response = await axios.get(`${BASE_URL}${API_PATH.NEWS}`)
    newsData.value = response.data
  } catch (error) {
    ElMessage.error('新闻加载失败：' + error.message)
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchData()
})

onActivated(() => {
  fetchData()
})
</script>

<style scoped>
</style>